<template>
    <van-nav-bar title="分销佣金" left-text="" left-arrow @click-left="goBack" />

	<div class="clear"></div>
    <div class="h50"></div>
    <div class="kickback_header">
        <div class="left">
            <div>可提现(元): <span>{{ sum }}</span></div>
            <div>累计提现(元): <span>{{ cash }}</span></div>
        </div>
        <div class="right" @click = "getMoney">
            立即提现
        </div>
    </div>
	<div class="kickback">
        <div class="item" v-for="(commission, index) in commissionList" :key="index">
            <div class="left">
                <div class="img">
                    <img :src="commission.product.thumbs_text" alt="">
                </div>
                <div class="content">
                    <div class="nickname">订单号：{{ commission.orderProduct.code }}</div>
                    <div class="tel">商品名称：{{ commission.product.name }}</div>
                </div>
            </div>
            <div class="right">
                <div class="status">{{ commission.status_text }}</div>
                <div class="money">{{ commission.amount }}</div>
            </div>
        </div>
	</div>
    
</template>

<script setup>
import { get } from 'vant/lib/utils';
import { onBeforeMount } from 'vue';


const { proxy } = getCurrentInstance();
const goBack = () => { proxy.$router.push('/business/index') }
const LoginUser = reactive(proxy.$cookies.get('LoginUser') ?? {});
const commissionList = ref([]);
const sum = ref(0);
const cash = ref(0);

const commissions = async () => {
    let result = await Api.commission({busid: LoginUser.id});
    if (result.code == 1) {
        commissionList.value = result.data.list;
        sum.value = result.data.sum;
        cash.value = result.data.cash;
    }
}

const getMoney = async () => {
    let result = await Api.getMoney({busid: LoginUser.id});
    if (result.code == 1) {
        success({
            message: result.msg,
            onClose: async () => {
                await commissions();
                location.reload();
            }
        });
        
    }
}

onBeforeMount(async() => {
    await commissions();
})

</script>

<style scoped>

.kickback{
    padding: 15px;
    background: #f7f8f7;
}

.kickback .item{
    background-color: #ffffff;
    display: flex;
    justify-content:space-between;
    align-items:center;
    padding: 10px;
    border-radius:5px;
    margin-bottom: 10px;
}

.kickback .item .left{
    display: flex;
    justify-content: flex-start;
    align-items: center;
    width: 80%;
}

.kickback .item .left .img{
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
}

.kickback .item .left .img img{
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.kickback .item .left .content{
    margin-left:10px;
    width: 80%;
}

.kickback .item .left .content .nickname{
    color: #323233;
    font-size: 13px;
}

.kickback .item .left .content .tel{
    font-size: 12px;
    color: #999;
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis;
}

.kickback .item .right{
    font-size: 12px;
    line-height: 24px;
    color: #999;
    width: 20%;
    text-align: center;
}

.kickback .item .right .money{
    color: #fe3961;
    font-weight: bold;
    font-size: 14px;
}

.kickback_header{
    background-color: #8bc34a;
    display: flex;
    justify-content:space-between;
    align-items:center;
    padding: 20px;
}

.kickback_header .left{
    color: #654f2c;
    font-size: 16px;
    line-height: 35px;
    display: flex;
    align-items:flex-start;
    flex-direction:column;
}

.kickback_header .left div:first-child span{
    color: #141212;
    font-size: 25px;
    display: inline-block;
}

.kickback_header .left div:last-child span{
    color: #141212;
    font-size: 16px;
    margin-left: 5px;
    display: inline-block;
}

.kickback_header .right{
    width: 80px;
    height: 30px;
    text-align: center;
    line-height: 30px;
    font-size: 16px;
    background-color: #323332;
    color: #8bc34a;
    border-radius: 15px;
}

</style>